package com.itqf.yun.vo;

import com.itqf.yun.nemus.ResponseCode;

/**
 * projectName: springboot_part
 *
 * @author: 赵伟风
 * time: 2021/9/18 11:39
 * description:
 *    以后我们编写实体类!
 *    一定要有无参数构造函数!
 *    一定要添加get/set方法
 */
public class R {


    /**
     * 返回的状态结果
     *   code = '004' 通用性的失败!
     *   code = '001' 通用性的成功!
     */
    private String code = "004" ;

    /**
     * 返回的描述信息
     *    描述内容自定义
     */
    private String msg = null;


    /**
     * 返回给前端的数据
     *    注意:返回类型可以是对象,也可能是对象集合!
     *    所以使用了通用类型Object类型!
     */
    private Object data = null;

    private Object user = null;

    public R(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.user = data;
    }

    public R() {
    }

    public static R OK(String msg,Object data){

        return new R("001", msg, data);
    }

    public static R OK(String msg){

        return OK(msg,null);
    }

    public static R OK(){

        return OK(null);
    }


    public static R FAIL(String msg,Object data){

        return new R("004", msg, data);
    }

    public static R FAIL(String msg){

        return FAIL(msg,null);
    }

    public static R FAIL(){

        return FAIL(null);
    }


    /**
     * 通用错误返回
     * @param responseCode
     * @return
     */
    public static  R COMMENTS(ResponseCode responseCode){

        return new R(responseCode.getCode(), responseCode.getMsg(), null);
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getUser() {
        return user;
    }

    public void setUser(Object user) {
        this.user = user;
    }
}
